import requests
import execjs

cookies = {
    'qm_check': 'A1sdRUIQChtxen8pI0dAOTQ+GRdzfX0QZlkBAwgGWCsiFQEGAAkQHAgdVldYSE5OBnEbEH1ZRl0GElQsSUhaQ0RtBWYAFEgWOVI3SFVacQR2AQgZFhRHBQ8NGxJYDxUCHAkcBBRVSldKBQ%3D%3D',
    'PHPSESSID': 'lh7m3lru0h3odpp9subatf28g8',
    'gr_user_id': '7f26da60-7274-43b7-9b32-17d2338db2e4',
    'synct': '1699510918.562',
    'syncd': '-379',
    'ada35577182650f1_gr_session_id': '26081e04-153a-40e7-9b39-8bfaeef2d0c6',
    'ada35577182650f1_gr_session_id_sent_vst': '26081e04-153a-40e7-9b39-8bfaeef2d0c6',
}

headers = {
    'authority': 'api.qimai.cn',
    'accept': 'application/json, text/plain, */*',
    'accept-language': 'zh-CN,zh;q=0.9',
    # 'cookie': 'qm_check=A1sdRUIQChtxen8pI0dAOTQ+GRdzfX0QZlkBAwgGWCsiFQEGAAkQHAgdVldYSE5OBnEbEH1ZRl0GElQsSUhaQ0RtBWYAFEgWOVI3SFVacQR2AQgZFhRHBQ8NGxJYDxUCHAkcBBRVSldKBQ%3D%3D; PHPSESSID=lh7m3lru0h3odpp9subatf28g8; gr_user_id=7f26da60-7274-43b7-9b32-17d2338db2e4; synct=1699510918.562; syncd=-379; ada35577182650f1_gr_session_id=26081e04-153a-40e7-9b39-8bfaeef2d0c6; ada35577182650f1_gr_session_id_sent_vst=26081e04-153a-40e7-9b39-8bfaeef2d0c6',
    'origin': 'https://www.qimai.cn',
    'sec-ch-ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-site',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
}

url = '/rank/index'

for i in range(1,5):

    params = {
        "brand": "free",
        "device": "iphone",
        "country": "cn",
        "genre": "36",
        "page":str(i)
    }
    analysis = execjs.compile(open('七麦数据请求参数逆向JS.js', 'r', encoding='utf-8').read()).call('encrypt_data',params,url)

    params['analysis'] = analysis

    response = requests.get('https://api.qimai.cn/rank/index', params=params, cookies=cookies, headers=headers).json()

    print(response['rankInfo'])


# 登录
# url = '/accountV1/login'
# data = {
#     'username': '18692739419',
#     'password': 'ZFC20030820zfc.',
# }
# analysis = execjs.compile(open('七麦数据请求参数逆向JS.js', 'r', encoding='utf-8').read()).call('encrypt_data',data,url)
#
# params = {
#     'analysis': analysis,
# }
# response = requests.post('https://api.qimai.cn/accountV1/login', params=params, cookies=cookies, headers=headers, data=data)
#
# print(response.json())

